

package assdraw.view;

import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.UIManager;

import assdraw.command.CircleCommand;
import assdraw.command.LineCommand;
import assdraw.command.RectCommand;
import assdraw.command.TriangleCommand;
import assdraw.event.ColorRadioListener;
import assdraw.model.Shape;



/**
 *
 * GUI, using NetBeans editor  
 */
public class MozMain extends javax.swing.JFrame {

	private static final long serialVersionUID = 1L;


	/** Creates new form mozMainFrame */
    public MozMain() {
    	super("ASS Draw");
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {

    	toolsButtonGroup = new javax.swing.ButtonGroup();
    	
        toolBar = new javax.swing.JToolBar();
        lineButton = new javax.swing.JToggleButton();
        rectangleButton = new javax.swing.JToggleButton();
        circleButton = new javax.swing.JToggleButton();
        triangleButton = new javax.swing.JToggleButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        groupButton = new javax.swing.JButton();
        ungroupButton = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        sizeUpButton = new javax.swing.JButton();
        sizeDownButton = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        zoomInButton = new javax.swing.JButton();
        zoomOutButton = new javax.swing.JButton();
        
        
        toolsButtonGroup.add(lineButton);
        lineButton.setSelected(true);
        lineButton.setText("Line");
        lineButton.setFocusable(false);
        lineButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        lineButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        lineButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lineButtonActionPerformed(evt);
            }
        });
        toolBar.add(lineButton);

        toolsButtonGroup.add(rectangleButton);
        rectangleButton.setText("Rectangle");
        rectangleButton.setFocusable(false);
        rectangleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        rectangleButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        rectangleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rectangleButtonActionPerformed(evt);
            }
        });
        toolBar.add(rectangleButton);

        toolsButtonGroup.add(circleButton);
        circleButton.setText("Circle");
        circleButton.setFocusable(false);
        circleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        circleButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        circleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                circleButtonActionPerformed(evt);
            }
        });
        toolBar.add(circleButton);

        toolsButtonGroup.add(triangleButton);
        triangleButton.setText("Triangle");
        triangleButton.setFocusable(false);
        triangleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        triangleButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        triangleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                triangleButtonActionPerformed(evt);
            }
        });
        toolBar.add(triangleButton);
        toolBar.add(jSeparator1);
        
        groupButton.setText("Group");
        groupButton.setFocusable(false);
        groupButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        groupButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        groupButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                groupButtonActionPerformed(evt);
            }
        });
        toolBar.add(groupButton);

        ungroupButton.setText("Ungroup");
        ungroupButton.setFocusable(false);
        ungroupButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        ungroupButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        ungroupButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ungroupButtonActionPerformed(evt);
            }
        });
        toolBar.add(ungroupButton);
        toolBar.add(jSeparator2);
        
        sizeUpButton.setText("Size Up");
        sizeUpButton.setToolTipText("");
        sizeUpButton.setFocusable(false);
        sizeUpButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        sizeUpButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        sizeUpButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sizeUpButtonActionPerformed(evt);
            }
        });
        toolBar.add(sizeUpButton);

        sizeDownButton.setText("Size Down");
        sizeDownButton.setFocusable(false);
        sizeDownButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        sizeDownButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        sizeDownButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sizeDownButtonActionPerformed(evt);
            }
        });
        toolBar.add(sizeDownButton);
        toolBar.add(jSeparator3);

        zoomInButton.setText("Zoom In");
        zoomInButton.setFocusable(false);
        zoomInButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        zoomInButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        zoomInButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zoomInButtonActionPerformed(evt);
            }
        });
        toolBar.add(zoomInButton);

        zoomOutButton.setText("Zoom Out");
        zoomOutButton.setFocusable(false);
        zoomOutButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        zoomOutButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);zoomOutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zoomOutButtonActionPerformed(evt);
            }
        });
        
        toolBar.add(zoomOutButton);        
        toolBar.setFloatable(false);

        
        getContentPane().setLayout(new BorderLayout());
                
        getContentPane().add(toolBar, java.awt.BorderLayout.NORTH);

        canvas = new DrawingCanvas();        
        getContentPane().add(canvas, java.awt.BorderLayout.CENTER);
        

        StatusBarPanel statusBar = new StatusBarPanel();
        canvas.getDrawing().addDrawingListener(statusBar);
        getContentPane().add(statusBar,BorderLayout.SOUTH);
        
        JPanel colorPanel = new JPanel();
        colorPanel.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        colorPanel.setLayout(new GridLayout(4,1));
        ButtonGroup colors = new ButtonGroup();
        
        JRadioButton color1 = new JRadioButton("Blue");
        color1.setActionCommand("Blue");
        color1.addActionListener(new ColorRadioListener(canvas));
        
        JRadioButton color2 = new JRadioButton("Green");
        color2.setActionCommand("Green");
        color2.addActionListener(new ColorRadioListener(canvas));
        
        JRadioButton color3 = new JRadioButton("Black");
        color3.setSelected(true);
        color3.setActionCommand("Black");
        color3.addActionListener(new ColorRadioListener(canvas));
        
        JRadioButton color4 = new JRadioButton("Pink");
        color4.setActionCommand("Pink");
        color4.addActionListener(new ColorRadioListener(canvas));
        
        colors.add(color1);
        colors.add(color2);
        colors.add(color3);
        colors.add(color4);
        
        colorPanel.add(color1);
        colorPanel.add(color2);
        colorPanel.add(color3);
        colorPanel.add(color4);
        getContentPane().add(colorPanel,BorderLayout.EAST);
        
        
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("ASS Draw");
        setLocationByPlatform(true);

        pack();
        setSize(this.getWidth(), 400);
        
    }// </editor-fold>

    private void lineButtonActionPerformed(java.awt.event.ActionEvent evt) {

        canvas.setCurrentCommand(new LineCommand());
    }

    private void rectangleButtonActionPerformed(java.awt.event.ActionEvent evt) {
        canvas.setCurrentCommand(new RectCommand());
    }

    private void circleButtonActionPerformed(java.awt.event.ActionEvent evt) {
        canvas.setCurrentCommand(new CircleCommand());
    }

    private void triangleButtonActionPerformed(java.awt.event.ActionEvent evt) {
        canvas.setCurrentCommand(new TriangleCommand());
    }

    private void groupButtonActionPerformed(java.awt.event.ActionEvent evt) {
        canvas.getDrawing().group(canvas.getSelected());
    }

    private void ungroupButtonActionPerformed(java.awt.event.ActionEvent evt) {
    	for(Shape s : canvas.getSelected()){
    		canvas.getDrawing().ungroup(s);
    	}
    	canvas.getSelected().clear();
    }

    private void sizeUpButtonActionPerformed(java.awt.event.ActionEvent evt) {
    	canvas.getDrawing().sizeUp(canvas.getSelected());
    }

    private void sizeDownButtonActionPerformed(java.awt.event.ActionEvent evt) {
    	canvas.getDrawing().sizeDown(canvas.getSelected());
    }

    private void zoomInButtonActionPerformed(java.awt.event.ActionEvent evt) {
        canvas.zoomIn();
    }

    private void zoomOutButtonActionPerformed(java.awt.event.ActionEvent evt) {
        canvas.zoomOut();
    }

    
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
    	try {
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		} catch (Exception e) {
			e.printStackTrace();
		}
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MozMain().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JToggleButton lineButton;
    private javax.swing.JToggleButton circleButton;
    private javax.swing.JButton groupButton;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToggleButton rectangleButton;
    private javax.swing.JToolBar toolBar;
    private javax.swing.JToggleButton triangleButton;
    private javax.swing.JButton ungroupButton;
    private javax.swing.JButton zoomInButton;
    private javax.swing.JButton zoomOutButton;
    private javax.swing.JButton sizeDownButton;
    private javax.swing.JButton sizeUpButton;
	private javax.swing.ButtonGroup toolsButtonGroup;
    
    private DrawingCanvas canvas;
    
    // End of variables declaration

}
